package cool.taomu.toolkit.rpc.thrift.server.service

import com.google.inject.Inject
import cool.taomu.toolkit.rpc.thrift.server.ClientInfoServerEventHandler
import java.util.Map
import org.apache.thrift.TProcessor
import org.apache.thrift.TProcessorFactory
import org.apache.thrift.server.THsHaServer
import org.apache.thrift.server.THsHaServer.Args
import org.eclipse.xtend.lib.annotations.Accessors

@Accessors
class TaomuThriftTHsHaServer {

	@Inject
	Map<String, Args> tHsHaArgs;

	def get(String name, TProcessor processor) {
		var arg = tHsHaArgs.get(name)
		arg.processorFactory(new TProcessorFactory(processor));
		var server = new THsHaServer(arg);
		server.serverEventHandler = new ClientInfoServerEventHandler();
		return server
	}

	def getFirst(TProcessor processor) {
		var arg = tHsHaArgs.get(tHsHaArgs.keySet.get(0))
		arg.processorFactory(new TProcessorFactory(processor));
		var server = new THsHaServer(arg);
		server.serverEventHandler = new ClientInfoServerEventHandler();
		return server
	}

}
